<template>
  <div class="userInfoAvatar">
    <el-dropdown>
      <span class="el-dropdown-link">
        <avatar class="avatar" />
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item>Action 1</el-dropdown-item>
          <el-dropdown-item>Action 2</el-dropdown-item>
          <el-dropdown-item>Action 3</el-dropdown-item>
          <el-dropdown-item disabled>Action 4</el-dropdown-item>
          <el-dropdown-item divided @click="handleLoginOutClick">
            退出登录
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { useRouter } from 'vue-router';

import localCache from '@/utils/cache';

export default defineComponent({
  setup() {
    const router = useRouter();
    const handleLoginOutClick = () => {
      localCache.deleteCache('token');
      router.push('/main');
    };
    return {
      handleLoginOutClick
    };
  }
});
</script>

<style scoped lang="less">
.avatar {
  width: 20px;
}
</style>
